<template>
  <div class="container">
    <div>
      <el-form ref="form" :model="form">
        <el-form-item label="考核单位：" label-width="110px">
          <el-select
            v-model="form.DW"
            placeholder="请选择"
            @change="getObjectList"
          >
            <el-option
              v-for="item in unitData"
              :key="item.CLIENT_NO"
              :label="item.UNITNAME"
              :value="item.CLIENT_NO"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="考核日期：" label-width="110px">
          <el-date-picker
            v-model="form.startDate"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="考核类型：" label-width="110px">
          <el-select
            v-model="form.LX"
            placeholder="请选择"
            @change="getObjectList"
          >
            <el-option
              v-for="item in typeData"
              :key="item.ID"
              :label="item.TYPENAME"
              :value="item.ID"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="考核项目：" label-width="110px">
          <el-select
            v-model="form.XM"
            placeholder="请选择"
            @change="getObjectTypelList(), getStandardList()"
          >
            <el-option
              v-for="item in itemData"
              :key="item.ID"
              :label="item.ITEMNAME"
              :value="item.ID"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="考核对象类型：" label-width="110px">
          <el-select
            v-model="form.DLX"
            placeholder="请选择"
            @change="getLevelList(), getStandardList()"
          >
            <el-option
              v-for="item in objectTypeData"
              :key="item.ID"
              :label="item.OBJECTTYPE"
              :value="item.ID"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="项目等级：" label-width="110px">
          <el-select
            v-model="form.DJ"
            placeholder="请选择"
            @change="getObjectList"
          >
            <el-option
              v-for="item in levelData"
              :key="item.ITEMLEVEL"
              :label="item.ITEMLEVEL"
              :value="item.ITEMLEVEL"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="考核标准：" label-width="110px">
          <el-select
            v-model="form.BZ"
            placeholder="请选择"
            @change="getObjectList"
          >
            <el-option
              v-for="item in standardData"
              :key="item.BH"
              :label="item.TITLE"
              :value="item.BH"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="考核对象：" label-width="110px">
          <el-select v-model="form.DX" placeholder="请选择"multiple 
            collapse-tags>
            <el-option
              v-for="item in objectData"
              :key="item.ID"
              :label="item.NAME"
              :value="item.ID"
            >
            </el-option>
          </el-select>
        </el-form-item> -->

        <el-row :gutter="20">
          <el-col :span="6">
            <el-form>
              <el-form-item label="抽样的方式：" label-width="110px">
                <el-select
                  style="width: 180px"
                  v-model="RANDOMTYPE"
                  placeholder="请选择"
                  @change="changeHandler"
                >
                  <el-option
                    v-for="item in RANDOMTYPEList"
                    :key="item.label"
                    :label="item.label"
                    :value="item.label"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-form>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form>
              <el-form-item label="" label-width="110px">
                <el-radio-group
                  v-model="RANDOMWAY"
                  v-if="this.RANDOMTYPE !== '地图绘制范围抽样'"
                >
                  <el-radio :label="1">按数量</el-radio>
                  <el-radio :label="2">按比例</el-radio>
                </el-radio-group>
                <el-button
                  v-if="this.RANDOMTYPE === '地图绘制范围抽样'"
                  type="success"
                  @click="showMapDialog"
                  >地图范围绘制</el-button
                >
              </el-form-item>
            </el-form>
          </el-col>
          <el-col :span="6" v-if="this.RANDOMTYPE !== '地图绘制范围抽样'">
            <el-form>
              <el-form-item>
                <el-input
                  style="width: 180px; height: 26px"
                  v-model="NUM"
                  :placeholder="NUMPlaceholder"
                ></el-input>
              </el-form-item>
            </el-form>
          </el-col>
        </el-row>

        <!-- <el-form-item label="是否随机抽样：" label-width="110px">
            <el-radio-group v-model="checkList3">
            <el-radio  label="是"></el-radio >
            <el-radio   label="否"></el-radio >
            </el-radio-group>
        </el-form-item> -->

        <el-form-item
          label="针对性条件："
          label-width="110px"
          v-if="this.RANDOMTYPE === '条件抽样'"
        >
          <el-radio-group v-model="CONDITION">
            <el-radio :label="1">考核覆盖率</el-radio>
            <el-radio :label="2">黑名单</el-radio>
            <el-radio :label="3">上次考核不达标</el-radio>
          </el-radio-group>
          <!-- <el-checkbox-group v-model="CONDITION">
            <el-checkbox label="考核覆盖率"></el-checkbox>
            <el-checkbox label="黑名单"></el-checkbox>
            <el-checkbox label="上次考核不达标"></el-checkbox>
          </el-checkbox-group> -->
        </el-form-item>
      </el-form>
      <el-row type="flex" justify="center">
        <el-col :span="24"
          ><div align="center">
            <el-button
              type="primary"
              @click="handleEdit"
              style="width: 100%; margin-bottom: 18px"
            >
              考 核 任 务 抽 样</el-button
            >
          </div></el-col
        >
      </el-row>
    </div>
    <!-- <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="options3.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div> -->
    <!-- 弹出框 -->
    <el-dialog
      :title="addDialogTitle"
      :visible.sync="isVisibleEdit"
      width="50%"
    >
      <el-row :gutter="10" type="flex" justify="space-around ">
        <el-col :span="5">
          <el-button type="success" @click="saveAdd">生成任务</el-button>
        </el-col>
        <el-col :span="5">
          <el-button type="warning" @click="getObjectList">重新抽样</el-button>
        </el-col>
        <el-col :span="5">
          <el-button type="primary" @click="exportExcel">导出任务</el-button>
        </el-col>
      </el-row>
      <el-table :data="objectData">
        <el-table-column
          prop="NAME"
          label="抽样对象"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="ITEMNAME"
          label="考核项目"
          align="center"
          :formatter="formatterITEMNAME"
        ></el-table-column>
        <el-table-column
          prop="ITEMLEVEL"
          label="项目等级"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="OBJECTTYPENAME"
          label="对象类型"
          align="center"
          :formatter="formatterOBJECTTYPENAME"
        ></el-table-column>
        <el-table-column
          prop="STANDARD"
          label="考核标准"
          align="center"
          :formatter="formatterSTANDARD"
        ></el-table-column>
        <el-table-column
          prop="RANDOMTYPE"
          label="抽样条件"
          align="center"
          :formatter="formatterRANDOMTYPE"
        ></el-table-column>
        <el-table-column
          prop="startDate"
          label="考核日期"
          align="center"
          :formatter="formatterKHDate"
        ></el-table-column>
      </el-table>
      <!-- <span slot="footer" class="dialog-footer">
        <el-button @click="isVisibleEdit = false">取 消</el-button>
        <el-button type="primary" @click="handleSubmit()">确 定</el-button>
      </span> -->
    </el-dialog>

    <!-- 弹出框 地图 -->
    <el-dialog
      @open="dialogOpenMap"
      :before-close="dialogCloseMap"
      title="道路展示"
      :visible.sync="fromMap.show"
      width="80%"
    >
      <div style="width: 100%; height: 500px">
        <div style="width: 50%; height: 100%; float: left" id="mapDialog"></div>
        <div style="width: 49%; height: 100%; float: left; margin-left: 1%">
          <el-table :data="objectData" height="100%">
            <!-- {ID: this.rid, NAME: this.rname, RGrade: this.rGrade, }) -->
            <el-table-column
              prop="NAME"
              label="对象名称"
              align="center"
            ></el-table-column>
            <el-table-column
              prop="ITEMLEVEL"
              label="对象等级"
              align="center"
            ></el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  @click="handleDeleteFromMap(scope.$index, scope.row)"
                  style="color: red"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="success" @click="saveAdd">生成任务</el-button>
        <el-button @click="fromMap.show = false">取 消</el-button>
        <!-- <el-button type="primary" @click="saveAdd"
          >确 定</el-button
        > -->
      </span>
    </el-dialog>
  </div>
</template>
<script>
import '@/assets/css/common.css'

import export2Excel from '@/utils/exportExcel/index.js'
// import { isRadialGradient } from 'html2canvas/dist/types/css/types/image'
// import OSS from 'ali-oss';
// import { time } from 'echarts';
// import { extend } from 'vue/types/umd';
export default {
  data () {

    return {
      startDate: '',
      standardData: [],
      typeData: [],
      unitData: [],
      itemData: [],
      objectData: [],
      objectTypeData: [],
      levelData: [],
      checkList1: ['道路机扫-道路'],
      checkList2: ['考核覆盖率'],
      checkList3: '是',
      clientData: [],
      currentPage: 1, //初始页
      pageSize: 10,    //    每页的数据
      originalData: [],
      tableData: [],
      select: {
        CPH: ''
      },
      isVisibleEdit: false,
      NUM: 1,
      NUMPlaceholder: '请输入',
      RANDOMTYPE: '',
      RANDOMTYPEList: [{
        value: 1,
        label: '全部抽样'
      }, {
        value: 2,
        label: '条件抽样'
        // }, {
        //   value: 3,
        //   label: '按比例抽取'
        // // }, {
        // //   value: 3,
        // //   label: '整群抽样'
        // // }, {
        // //   value: 4,
        // //   label: '机械抽样'
      }, {
        value: 3,
        label: '地图绘制范围抽样'
      }],
      RANDOMWAY: 1,
      CONDITION: 1,
      labelwidth: 100,
      addDialogTitle: '',
      form: {
        WaterCPH: "",
        WaterTime: "",
        CreateTime: "",
        WaterNumber: "",
        WaterLocation: "",
        WaterCphType: "",
        WaterPeople: "",
        WaterPeopleID: "",
      },
      fromMap: {
        dataSetDic: {},
        arrayRoadName: [],
        arrayRoadNameLabel: [],
        show: false,
        dataTable: [],
        roadName: '',
        selectedPath: '',
        polyline: null,
      },
      tableData: [],
      contentTags: ['道路机扫-道路', '环卫作业公司', '公厕'],
      contentTags2: ['考核覆盖率', '黑名单', '上次考核不达标'],
      conditionTags: ['按数量抽取', '按比例抽取', '按地图绘制范围'],
      inputVisible: false,
      inputValue: '',
      isRandom: false,
      isRandomInput: ''
    }
  },
  created () {

    // if (localStorage.getItem('CTYPE') == '0') {
    //   this.rolelevel.shift()
    // } else if (localStorage.getItem('CTYPE') != '-1') {
    //   this.rolelevel = []
    // }
    // this.getClientRoleList()
  },
  mounted () {
    this.getUnitList()
    this.getTypeList()
    this.getItemList()
  },
  methods: {


    // 获取考核单位列表
    async getUnitList () {
      var url = 'Assess/GetUnit_Assess?UNITNAME='
      let { data } = await this.$Http.get(url)
      this.unitData = data
      this.form.DW = data[0].CLIENT_NO
    },
    // 获取考核类型列表
    async getTypeList () {
      var url = 'Assess/GetCheckType_Assess?TYPENAME='
      let { data } = await this.$Http.get(url)
      this.typeData = data
    },
    // 获取考核项目列表
    async getItemList () {
      var url = 'Assess/GetCheckItem_Assess?KEY='
      let { data } = await this.$Http.get(url)
      this.itemData = data
    },
    // 获取考核对象类型
    async getObjectTypelList () {
      var url = 'Assess/GetObjectType_Assess?ITEMID=' + this.form.XM + '&OBJECTTYPE='
      let { data } = await this.$Http.get(url)
      this.objectTypeData = data
    },
    // 获取考核项目等级列表
    async getLevelList () {
      var url = 'Assess/GetItemLevelList_Assess?CLIENT_NO=' + this.form.DW + '&ITEMID=' + this.form.XM + '&OBJECTTYPE=' + this.form.DLX
      let { data } = await this.$Http.get(url)
      this.levelData = data
    },
    // 获取考核标准列表
    async getStandardList () {
      var url = 'Assess/GetStandardDetail_Assess?ITEMID=' + this.form.XM + '&OBJECTTYPEID=' + this.form.DLX + '&KEY='
      let { data } = await this.$Http.get(url)
      this.standardData = data
    },
    // 获取考核对象列表
    async getObjectList () {
      this.objectData = []
    },
    async getObjectList111 () {
      this.objectData = []
      var way = '按数量'
      if (this.RANDOMWAY == 1) {

        var way = '按数量'
      } else {
        var way = '按比例'
      }
      var url = 'Assess/GetTaskRandom_Assess?CLIENT_NO=' + this.form.DW + '&CHECKTYPEID=' + this.form.LX + '&WORKDATE=' + this.form.startDate
        + '&CHECKITEMID=' + this.form.XM + '&CHECKOBJECTTYPEID=' + this.form.DLX + '&ITEMLEVEL=' + this.form.DJ
        + '&RANDOMTYPE=' + this.RANDOMTYPE + '&RANDOMWAY=' + way + '&NUM=' + this.NUM + '&CONDITION=' + this.CONDITION
      let { data } = await this.$Http.get(url)
      this.objectData = data
    },
    formatterITEMNAME (row, obj, item, index) {
      if (!item) {
        return this.RANDOMTYPE
      } else {
        return item
      }
    },
    formatterOBJECTTYPENAME (row, obj, item, index) {
      if (!item) {
        return this.form.DLX
      } else {
        return item
      }
    },
    formatterSTANDARD (row, obj, item, index) {
      if (!item) {
        if (this.standardData) {
          return this.standardData.filter(item => item.BH.includes(this.form.BZ))[0].TITLE
        } else {
          return ''
        }
      } else {
        return item
      }
    },
    formatterRANDOMTYPE (row, obj, item, index) {
      if (!item) {
        return this.RANDOMTYPE
      } else {
        return item
      }
    },
    formatterKHDate (row, obj, item, index) {
      if (!item) {
        return this.form.startDate
      } else {
        return item
      }
    },
    handleEdit () {
      if (this.RANDOMTYPE != '地图绘制范围抽样') {
        this.getObjectList111()
      }
      this.addDialogTitle = '考核内容详情'
      this.isVisibleEdit = true;
    },

    // 生成考核任务
    async saveAdd () {
      var str = '';
      this.objectData.forEach(element => {
        str = str + element.ID + ','
      });
      str = str.substring(0, str.length - 1);
      this.form.DID = str
      this.$axios({
        url: 'Assess/SaveTaskInfo_Assess',
        method: 'post',
        data: {
          ID: '0',
          WORKDATE: this.form.startDate,
          CHECKTYPEID: this.form.LX,
          CHECKITEMID: this.form.XM,
          CHECKOBJECTTYPEID: this.form.DLX,
          ITEMLEVEL: this.form.DJ,
          CLIENT_NO: this.form.DW,
          RANDOMTYPE: this.RANDOMTYPE,
          LEVEL: this.form.DJ,
          STANDARDIDS: this.form.BZ,
          OBJECTIDS: this.form.DID,
          CREATENO: localStorage.getItem('CLIENT_NO'),
          INSYSTEMID: '0',
        },

      }).then((res) => {
        if (res.data.IsSucess) {
          this.$message.success('考核任务生成成功');
          this.isVisibleEdit = false;
          this.fromMap.show = false
        } else {
          this.$message.error('考核任务生成失败');
        }
      })

    },
    changeHandler () {
    },
    showMapDialog (index, row) {
      // 需要修改地图比例
      this.fromMap.show = true
      // this.fromMap.roadName = row.RNAME
      // this.fromMap.roadName = '中南二街1'
      // this.getRoadGPS(row, 1);
    },
    dialogCloseMap () {
      this.fromMap.show = false
      this.fromMap.map.clearOverlays()
    },
    dialogOpenMap () {
      setTimeout(() => {
        if (!this.fromMap.map) {
          this.mapDialogShow()
        }
        if (this.fromMap.DLX === this.form.DLX) {
          return
        }
        this.fromMap.DLX = this.form.DLX
        console.log(this.form.DLX)
        switch (this.form.DLX) {
          case '1':
            // 机扫道路
            this.getRoadJS();
            break;
          case '2':
            // 机扫车辆
            break;
          case '3':
            // 人工道路
            this.getRoadRG();
            break;
          case '4':
            // 人工工人
            break;
          case '5':
            // 公厕
            this.getWC();
            break;
          case '6':
            // 垃圾收运车辆
            break;
          case '7':
            // 垃圾收运垃圾点
            this.getPointRubbishSY();
            break;
          case '8':
            // 转运站
            this.getPlaceStation();
            break;
          case '9':
            // 处理厂
            this.getPlaceFactory();
            break;
          case '10':
            // 垃圾分类 垃圾点
            this.getPointRubbishFL();
            break;
          case '11':
            // 果皮箱 垃圾点
            break;
          case '12':
            // 大件垃圾 垃圾点
            break;
          default:
            break;
        }

      }, 1000)
    },
    async mapDialogShow () {
      this.fromMap.map = new BMap.Map('mapDialog')// 创建Map实例
      // 初始化地图,设置中心点坐标和地图级别
      this.fromMap.map.centerAndZoom(
        new BMap.Point(
          localStorage.getItem("LNG"),
          localStorage.getItem("LAT")
        ),
        16
      );
      this.fromMap.map.enableScrollWheelZoom(true)//开启鼠标滚轮缩放
    },
    handleDeleteFromMap (index, row) {
      this.objectData.splice(index, 1)
      console.log(this.objectData)
    },


    // 道路机扫
    async getRoadJS () {
      this.objectData = []
      // this.fromMap = {}
      this.fromMap.arrayRoadName = []
      this.fromMap.map.clearOverlays()
      var url = "Vehicle/GetClientRoadGPSInfoPB?ClientNO=" + this.form.DW
      const { data } = await this.$Http.get(url)

      var rid = data[0].ROUDID
      var rname = data[0].NAME
      var rGrade = data[0].RGrade
      var points = []
      var pointAll = []

      for (let index = 0; index < data.length; index++) {
        const element = data[index];
        if (element.ROUDID === rid && element.NAME === rname) {
          points.push(new BMap.Point(element.LNG, element.LAT))
          pointAll.push(new BMap.Point(element.LNG, element.LAT))
        } else {
          this.drawRoad(rid, rname, rGrade, points)

          rid = element.ROUDID
          rname = element.NAME
          rGrade = element.RGrade
          points = []
          points.push(new BMap.Point(element.LNG, element.LAT))
          // districtName = element.行政区划
        }
        element.numS = points.length
      }
      this.drawRoad(rid, rname, rGrade, points)
      this.fromMap.map.setViewport(pointAll);

      // this.getRoadUnSettingInitial()
    },
    // 道路人工
    async getRoadRG () {
      this.objectData = []
      // this.fromMap = {}
      this.fromMap.arrayRoadName = []
      this.fromMap.map.clearOverlays()
      var url = "Worker/GetClientRoadGPSInfoPB?ClientNO=" + this.form.DW
      const { data } = await this.$Http.get(url)
      var rid = data[0].ROUDID
      var rname = data[0].NAME
      var rGrade = data[0].RGrade
      var points = []
      var pointAll = []

      for (let index = 0; index < data.length; index++) {
        const element = data[index];
        if (element.ROUDID === rid && element.NAME === rname) {
          points.push(new BMap.Point(element.LNG, element.LAT))
          pointAll.push(new BMap.Point(element.LNG, element.LAT))
        } else {
          this.drawRoad(rid, rname, rGrade, points)

          rid = element.ROUDID
          rname = element.NAME
          rGrade = element.RGrade
          points = []
          points.push(new BMap.Point(element.LNG, element.LAT))
          // districtName = element.行政区划
        }
        element.numS = points.length
      }
      this.drawRoad(rid, rname, rGrade, points)
      this.fromMap.map.setViewport(pointAll);

      // this.getRoadUnSettingInitial()
    },
    drawRoad (rid, rname, rGrade, points) {
      if (this.form.DJ != undefined && this.form.DJ != '全部') {
        if (this.form.DJ != rGrade) {
          return;
        }
      }
      // 道路画线
      var polyline = new BMap.Polyline(points, { strokeColor: "#32CD32", strokeWeight: 4, strokeOpacity: 0.5 });   //创建折线
      this.fromMap.map.addOverlay(polyline);

      polyline.rid = rid
      polyline.rname = rname
      polyline.rGrade = rGrade

      var lineCenter = polyline.getBounds().getCenter()

      this.fromMap.arrayRoadName.push({
        geometry: {
          type: 'Point',
          coordinates: [lineCenter.lng, lineCenter.lat]
        },
        text: rname,
        roadID: rid
      })

      var label = new BMap.Label(rname, { position: lineCenter, offset: new BMap.Size(-20, -10) })
      polyline.LabelP = label
      label.rGrade = rGrade

      label.setStyle({
        borderColor: '#fff',
        padding: '2px',
        borderRadius: '5px', // 可能内存成本很高
      })
      this.fromMap.map.addOverlay(label);
      this.fromMap.arrayRoadNameLabel.push(label)
      // if (!this.checkedRoadName) {
      //   label.hide()
      // }

      const _this = this
      polyline.addEventListener('click', function (e) {
        var isRepeat = false
        _this.objectData.forEach(element => {
          if (this.rid === element.ID) {
            _this.$message.warning('该被考核对象已添加，请勿重复添加');
            isRepeat = true
            return
          }
        });
        if (!isRepeat) {
        _this.objectData.push({ ID: this.rid, NAME: this.rname, ITEMLEVEL: this.rGrade, })
        }
        // _this.addRoudInfo(this.rname, 1)
      })
    },

    //获取垃圾点列表
    async getPointRubbishSY () {
      var url = 'CarService/getPlaceGarbagePoint?CLIENT_NO=' + this.form.DW
      const { data } = await this.$Http.get(url)
      if (data.length > 0) {
        data[0].img = 'point/垃圾收集点'
        data.forEach(element => {
          element.NAME = element.POINTNAME
        });
        this.drawMapV([data])
      } else {
        this.$message.warning('当前条件未查询到垃圾收运垃圾点数据');
      }
    },
    async getPointRubbishFL () {
      var url = 'RubbishClassification/GetRubbishScoreRoom?ClientNo=' + this.form.DW
      const { data } = await this.$Http.get(url)
      if (data.length > 0) {
        data[0].img = 'new/分类房'
        this.drawMapV([data])
      } else {
        this.$message.warning('当前条件未查询到垃圾收运垃圾点数据');
      }
    },
    //获取转运站
    async getPlaceStation () {
      var url = 'CarService/getPlaceStation?CLIENT_NO=' + this.form.DW
      const { data } = await this.$Http.get(url)
      // var pointAll = []
      var listChuyu = [], listQita = [], listKehuishou = [], listYouhai = [];
      if (data.length > 0) {
        data.forEach(item => {
          // pointAll.push(new BMap.Point(item.LONGITUDE, item.LATITUDE))
          if (this.form.DJ != undefined && this.form.DJ != '全部') {
            if (this.form.DJ != item.TYPE) {
              return;
            }
          }
          switch (item.TYPE) {
            case '厨余垃圾中转站': {
              item.img = '厨余垃圾中转站'
              listChuyu.push(item);
              break;
            }
            case '其他垃圾中转站': {
              item.img = '其他垃圾中转站'
              listQita.push(item);
              break;
            }
            case '可回收垃圾中转站': {
              item.img = '可回收垃圾中转站'
              listKehuishou.push(item);
              break;
            }
            case '有害垃圾中转站': {
              item.img = '有害垃圾中转站'
              listYouhai.push(item);
              break;
            }
          }
        });
        // this.fromMap.map.setViewport(pointAll);
        this.drawMapV([listChuyu, listQita, listKehuishou, listYouhai])
      } else {
        this.$message.warning('当前条件未查询到转运站数据');
      }
    },
    //获取处理厂
    async getPlaceFactory () {
      var url = 'CarService/getPlaceFactory?CLIENT_NO=' + this.form.DW
      const { data } = await this.$Http.get(url)
      // var pointAll = []
      // var listChuyu = [], listQita = [], listKehuishou = [], listYouhai = [];
      if (data.length > 0) {
        data[0].img = 'markerImageCLC'
        //   data.forEach(item => {
        //   if (!item.NAME.includes(this.select.name)) {
        //     return;
        //   }
        //   switch (item.TYPE) {
        //       case '厨余垃圾处理厂':{
        //         item.img = '厨余垃圾'
        //         listChuyu.push(item);
        //         break;
        //         }
        //       case '其他垃圾处理厂':{
        //         item.img = '其他垃圾'
        //         listQita.push(item);
        //         break;}
        //       case '可回收垃圾处理厂':{
        //         item.img = '可回收垃圾'
        //         listKehuishou.push(item);
        //         break;}
        //       case '有害垃圾处理厂':{
        //         item.img = '有害垃圾'
        //         listYouhai.push(item);
        //         break;}
        //     }
        // });
        // this.drawMapV([listChuyu, listQita, listKehuishou, listYouhai])
        this.drawMapV([data])
      } else {
        this.$message.warning('当前条件未查询到处理厂数据');
      }

    },
    //获取公厕列表
    async getWC () {
      var url = 'CarService/getPlaceToilet?CLIENT_NO=' + this.form.DW
      const { data } = await this.$Http.get(url)
      // var pointAll = []
      if (data.length > 0) {
        data[0].img = 'duli'
        this.drawMapV([data])
      } else {
        this.$message.warning('当前条件未查询到公厕数据');
      }
    },
    // 显示标记点
    drawMapV (arrayData) {
      // 销毁旧图层
      for (var key in this.fromMap.dataSetDic) {
        this.fromMap.dataSetDic[key].set([]);
      }

      //因为需要加载不同的图片，所以将车辆数据按车辆类型、是否在线分成不同数组this.Data.arrayForType
      arrayData.forEach(arrayDataForSameIcon => {
        //如果数据中无数据，退出循环
        if (arrayDataForSameIcon.length == 0) {
          return;
        }

        const _self = this;

        let img = new Image();
        // img.src = require(arrayDataForSameIcon[0].img)
        img.src = require('@/assets/img/marker/' + arrayDataForSameIcon[0].img + '.png')
        // img.src = require('@/assets/img/marker/' + arrayDataForSameIcon[0].img + '.png')
        // console.log('@/assets/img/marker/' + arrayDataForSameIcon[0].img+ '.png')
        // img.src = require('@/assets/img/marker/厨余垃圾中转站.png')
        img.onload = function () {
          //循环加载同一张图片的车辆数据
          let arrayImage = arrayDataForSameIcon.map(v => {
            v.geometry = {
              type: 'Point',
              coordinates: [v.LONGITUDE, v.LATITUDE]
            }
            v.icon = img;
            v.text = v.NAME;
            return v;
          })

          let key = arrayDataForSameIcon[0].TYPE

          if (_self.fromMap.dataSetDic.hasOwnProperty(key)) {

            _self.fromMap.dataSetDic[key].set(arrayImage);
            // _self.MapV.iconLayerDic[key].show()
            // _self.MapV.textLayerDic[key].show()

          } else {

            let optionsICON = {
              draw: 'icon',
              width: 35, // 规定图像的宽度
              height: 35, // 规定图像的高度
              // offset: { // 文本便宜值
              //   x: 0,
              //   y: 20
              // }
              methods: {
                click: function (e) {
                  if (e) {
                    var isRepeat = false
                    _self.objectData.forEach(element => {
                      if (e.ID === element.ID) {
                        _self.$message.warning('该被考核对象已添加，请勿重复添加');
                        isRepeat = true
                        return
                      }
                    });
                    console.log(e)
                    if (!isRepeat) {
                    switch (_self.form.DLX) {
                      case '5':
                        _self.objectData.push({ ID: e.ID, NAME: e.NAME, ITEMLEVEL: e.LEVEL, })
                        break;
                      case '7':
                        // 垃圾收运 垃圾点
                        _self.objectData.push({ ID: e.ID, NAME: e.NAME, ITEMLEVEL: '', })
                        break;
                      case '8':
                        _self.objectData.push({ ID: e.ID, NAME: e.NAME, ITEMLEVEL: e.TYPE, })
                        break;
                      case '9':
                        _self.objectData.push({ ID: e.ID, NAME: e.NAME, ITEMLEVEL: e.TYPE, })
                        break;
                      case '10':
                        // 垃圾分类 垃圾点
                        _self.objectData.push({ ID: e.ID, NAME: e.NAME, ITEMLEVEL: e.垃圾点类型, })
                        break;
                      default:
                        break;
                    }
                    }
                    // _self.objectData.push({ ID: e.ID, NAME: e.NAME, RGrade: e.LEVEL, })
                    // _self.clickMarkerForMapV(e);
                  }
                }
              },
            }

            let optionsTEXT = {
              draw: 'text',
              size: 14,
              avoid: true, // 开启文本标注避让
              textBaseline: 'middle',
              offset: { // 文本便宜值
                x: 0,
                y: 30
              }
            }

            let dataSet = new mapv.DataSet(arrayImage);

            _self.fromMap.dataSetDic[key] = dataSet;
            new mapv.baiduMapLayer(_self.fromMap.map, dataSet, optionsICON)
            new mapv.baiduMapLayer(_self.fromMap.map, dataSet, optionsTEXT)
          }
        }
      });
    },




    // 导入Excel
    onChange (file, fileList) {
      //  console.log(fileList);
      this.fileData = file; // 保存当前选择文件
      this.readExcel(); // 调用读取数据的方法
    },
    // 导出Excel
    exportExcel () {
      let excelName = '考核内容详情'
      const tHeader = ['抽样对象', '考核项目', '项目等级', '对象类型', '考核标准', '抽样条件', '考核日期']
      const filterVal = ['NAME', 'ITEMNAME', 'ITEMLEVEL', 'OBJECTTYPENAME', 'STANDARD', 'RANDOMTYPE', 'startDate']
      export2Excel(tHeader, filterVal, this.objectData, excelName)
    },
    // 模糊查询
    screeningData () {
      this.tableData = this.originalData
      if (this.select.CPH) this.tableData = this.tableData.filter(item => item.CPH.includes(this.select.CPH))
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getlistdata();
    },
    handleSizeChange (size) {
      this.pageSize = size;
      console.log(this.pageSize)
    }
  }
}
</script>
<style>
.el-form-item__label {
  text-align: left;
}
/* .el-checkbox {
  color: #fff;
}
.el-checkbox__label {
  color: #fff !important;
} */
.content {
  overflow-y: scroll;
}
.el-col-6 {
  width: 350px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
.el-form-item label {
  width: 80px;
}
.el-tag + .el-tag {
  margin-left: 10px;
}
.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}
.input-new-tag {
  height: 32px;
  line-height: 30px;
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}
.aroundtop {
  padding: 10px;
  background-color: #007acc;
  height: 100%;
  border-radius: 5px;
}
.el-icon-speed {
  color: #fff;
  font-size: 18px;
  font-weight: bold;
  height: 30px;
  line-height: 28px;
  text-align: center;
  vertical-align: middle;
  cursor: pointer;
  margin: 10px 20px 10px 20px;
}
</style>